package zengqiang.day05

fun main(args: Array<String>) {

    //1. find只会查找第一个，filter是查找出所有符合条件的
    var list= listOf<String>("张三","张思","呵呵")
    var list1= listOf<String>("张五","张六","呵呵1")
    var r1=list.find {
        it.startsWith("张")
    }
    println(r1) //张三

    //2. filter
    var r2=list.filter {
        it.startsWith("张")//[张三, 张思]
    }
    println(r2)


    //3. 查找两个集合并把符合条件的合并到一起
    val mutList= mutableListOf<String>()
    list.filterTo(mutList){
        it.startsWith("张")
    }
    list1.filterTo(mutList){
        it.startsWith("张")
    }
    println(mutList) //[张三, 张思, 张五, 张六]

    //4.根据角标查询
    var r3=list.filterIndexed{
        index, s ->index%2==1
    }
    println(r3) //[张思]
}